package com.atguigu.imperial.court.service.impl;

import com.atguigu.imperial.court.dao.api.EmpDao;
import com.atguigu.imperial.court.dao.impl.EmpDaoImpl;
import com.atguigu.imperial.court.entity.Emp;
import com.atguigu.imperial.court.exception.LoginFailedException;
import com.atguigu.imperial.court.service.api.EmpService;
import com.atguigu.imperial.court.util.ImperialCourtConst;
import com.atguigu.imperial.court.util.MD5Util;

import javax.security.auth.login.LoginException;

public class EmpServiceImpl implements EmpService {
    private EmpDao empDao=new EmpDaoImpl();
    @Override
    public Emp getEmpByLoginAccount(String loginAccount, String loginPassword) {


        //1.对密码执行加密
        String encodedPassword = MD5Util.encode(loginPassword);
        Emp emp=empDao.selectEmpByLoginAccount(loginAccount,encodedPassword);
        //2.根据账号和密码查询数据库
        if(emp!=null) {
            //3.检查Emp 对象是否为 null
            return emp;
        }else {//a.不为null： 返回 Emp
            //b.为 null: 抛出登录失败异常
            throw new LoginFailedException(ImperialCourtConst.LOGIN_FAILED_MESSAGE);
        }
    }
}
